"""
pom
page object model  页面模型，
1. 先把每一个页面 封装到类中
2. 页面中的每个组件作为属性


baseActivity 作为所有页面对象的基类
在基类中定义driver
"""

from common.driver_manage import DriverManage

class BaSeActivity:
    driver = DriverManage.get_driver()
    def __init__(self):
        self._toast_xpath = '//android.widget.Toast'

    @property
    def get_Toast(self):
        return self.driver.find_element_by_xpath('//android.widget.Toast')

    def swipe(self,direction:str):
        direction = direction.lower()
        windows_size = self.driver.get_window_size()
        x = windows_size['width']-1
        y = windows_size['height']-1

        if direction == 'left':
            self.driver.swipe(start_x=x,start_y=y/2,end_x=0,end_y=y/2,duration=1000)
        elif direction == "up":
            self.driver.swipe(start_x=0,start_y=y,end_x=0,end_y=0,duration=1000)
        elif direction == "right":
            self.driver.swipe(start_x=0,start_y=y/2,end_x=x,end_y=y/2,duration=1000)
        elif direction == "down":
            self.driver.swipe(start_x=0,start_y=0,end_x=0,end_y=y,duration=1000)
        else:
            raise Exception('参数输入有误')
